package com.love.utils;

import java.util.regex.Pattern;

public class StringHelper {

	private static Pattern numPattern = Pattern.compile("[\\d]{1,}");

	private static Pattern phonePattern = Pattern.compile("1[3578][\\d9]{9}");

	private static Pattern emailPattern = Pattern.compile("\\w{1,}@\\w{1,20}\\.\\w{1,10}");

	private static Pattern passwordPattern = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,20}$");
	
	/**
	 * 验证是不是数字
	 * @param num
	 * @return
	 */
	public static boolean checkNumber(String num) {
		return numPattern.matcher(num).matches();
	}

	public static boolean checkNumberV2(String num) {
		if (num.substring(0, 1).equals("0")) {
			return false;
		}
		return numPattern.matcher(num).matches();
	}

	/**
	 * 验证是否为手机号
	 * @param key
	 * @return
	 */
	public static boolean checkPhone(String phone) {
		return phonePattern.matcher(phone).matches();
	}

	/**
	 * 验证是否为邮箱
	 * @param key
	 * @return
	 */
	public static boolean checkEmail(String email) {
		return emailPattern.matcher(email).matches();
	}
	
	/**
	 * 验证是否为密码格式：6-20数字字母组合
	 * @param password
	 * @return
	 */
	public static boolean checkPassword(String password){
		return passwordPattern.matcher(password).matches();
	}
	
	public static void main(String[] args) {
		System.out.println(checkPassword(""));
	}
}
